home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / editors / emcs1857 / 1857sr~1.zoo / src / search.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-02  |  36.8 KB  |  1,303 lines

  1. /* String search routines for GNU Emacs.
  2.    Copyright (C) 1985, 1986, 1987, 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* Modified 1991 for 8-bit character support by Howard Gayle.
  22.  *  See chartab.c for details. */
  23.  
  24.  
  25. #include "config.h"
  26. #include "lisp.h"
  27. #include "syntax.h"
  28. #include "buffer.h"
  29. #include "casetab.h"
  30. #include "chartab.h"
  31. #include "commands.h"
  32. #include "regex.h"
  33. #include "sorttab.h"
  34.  
  35. #define max(a, b) ((a) > (b) ? (a) : (b))
  36. #define min(a, b) ((a) < (b) ? (a) : (b))
  37.  
  38. /* We compile regexps into this buffer and then use it for searching. */
  39.  
  40. struct re_pattern_buffer searchbuf;
  41.  
  42. char_t search_fastmap[0400];
  43.  
  44. /* Last regexp we compiled */
  45. Lisp_Object last_regexp;
  46.  
  47.  
  48. /* Every call to re_match, etc., must pass &search_regs as the regs argument
  49.  unless you can show it is unnecessary (i.e., if re_match is certainly going
  50.  to be called again before region-around-match can be called).  */
  51.  
  52. static struct re_registers search_regs;
  53.  
  54. /* error condition signalled when regexp compile_pattern fails */
  55.  
  56. Lisp_Object Qinvalid_regexp;
  57.  
  58. /* Compile a regexp and signal a Lisp error if anything goes wrong.  */
  59.  
  60. compile_pattern (pattern, bufp, sorttab)
  61.      Lisp_Object pattern;
  62.      struct re_pattern_buffer *bufp;
  63.      struct Lisp_Sorttab *sorttab;
  64. {
  65.   char *val;
  66.   Lisp_Object dummy;
  67.  
  68.   /* Sort table used for last regexp compilation: */
  69.   static struct Lisp_Sorttab *last_sort_table;
  70.  
  71.   if (EQ (pattern, last_regexp)
  72.       && sorttab == last_sort_table)
  73.     return;
  74.   last_regexp = Qnil;
  75.   last_sort_table = sorttab;
  76.   val = re_compile_pattern_sort (XSTRING (pattern)->data,
  77.                  XSTRING (pattern)->size,
  78.                  bufp, sorttab);
  79.   if (val)
  80.     {
  81.       dummy = build_string (val);
  82.       while (1)
  83.     Fsignal (Qinvalid_regexp, Fcons (dummy, Qnil));
  84.     }
  85.   last_regexp = pattern;
  86.   last_sort_table = sorttab;
  87.   return;
  88. }
  89.  
  90. /* Error condition used for failing searches */
  91. Lisp_Object Qsearch_failed;
  92.  
  93. Lisp_Object
  94. signal_failure (arg)
  95.      Lisp_Object arg;
  96. {
  97.   Fsignal (Qsearch_failed, Fcons (arg, Qnil));
  98.   return Qnil;
  99. }
  100.  
  101. DEFUN ("looking-at", Flooking_at, Slooking_at, 1, 1, 0,
  102.   "t if text after point matches regular expression PAT.")
  103.   (string)
  104.      Lisp_Object string;
  105. {
  106.   Lisp_Object val;
  107.   unsigned char *p1, *p2;
  108.   int s1, s2;
  109.   register int i;
  110.  
  111.   CHECK_STRING (string, 0);
  112.   compile_pattern (string, &searchbuf, current_sort_table ());
  113.  
  114.   immediate_quit = 1;
  115.   QUIT;            /* Do a pending quit right away, to avoid paradoxical behavior */
  116.  
  117.   /* Get pointers and sizes of the two strings
  118.      that make up the visible portion of the buffer. */
  119.  
  120.   p1 = BEGV_ADDR;
  121.   s1 = GPT - BEGV;
  122.   p2 = GAP_END_ADDR;
  123.   s2 = ZV - GPT;
  124.   if (s1 < 0)
  125.     {
  126.       p2 = p1;
  127.       s2 = ZV - BEGV;
  128.       s1 = 0;
  129.     }
  130.   if (s2 < 0)
  131.     {
  132.       s1 = ZV - BEGV;
  133.       s2 = 0;
  134.     }
  135.   
  136.   val = (0 <= re_match_2 (&searchbuf, p1, s1, p2, s2,
  137.               point - BEGV, &search_regs, ZV - BEGV)
  138.      ? Qt : Qnil);
  139.   for (i = 0; i < RE_NREGS; i++)
  140.     if (search_regs.start[i] >= 0)
  141.       {
  142.     search_regs.start[i] += BEGV;
  143.     search_regs.end[i] += BEGV;
  144.       }
  145.   immediate_quit = 0;
  146.   return val;
  147. }
  148.  
  149. DEFUN ("string-match", Fstring_match, Sstring_match, 2, 3, 0,
  150.   "Return index of start of first match for REGEXP in STRING, or nil.\n\
  151. If third arg START is non-nil, start search at that index in STRING.\n\
  152. For index of first char beyond the match, do (match-end 0).\n\
  153. match-end and match-beginning also give indices of substrings\n\
  154. matched by parenthesis constructs in the pattern.")
  155.   (regexp, string, start)
  156.      Lisp_Object regexp, string, start;
  157. {
  158.   int val;
  159.   int s;
  160.  
  161.   CHECK_STRING (regexp, 0);
  162.   CHECK_STRING (string, 1);
  163.  
  164.   if (NULL (start))
  165.     s = 0;
  166.   else
  167.     {
  168.       int len = XSTRING (string)->size;
  169.  
  170.       CHECK_NUMBER (start, 2);
  171.       s = XINT (start);
  172.       if (s < 0 && -s <= len)
  173.     s = len - s;
  174.       else if (0 > s || s > len)
  175.     args_out_of_range (string, start);
  176.     }
  177.  
  178.   compile_pattern (regexp, &searchbuf, current_sort_table ());
  179.   immediate_quit = 1;
  180.   val = re_search (&searchbuf, XSTRING (string)->data, XSTRING (string)->size,
  181.                    s, XSTRING (string)->size - s, &search_regs);
  182.   immediate_quit = 0;
  183.   if (val < 0) return Qnil;
  184.   return make_number (val);
  185. }
  186.  
  187. scan_buffer (target, pos, cnt, shortage)
  188.      int *shortage, pos;
  189.      register int cnt, target;
  190. {
  191.   int lim = ((cnt > 0) ? ZV - 1 : BEGV);
  192.   int direction = ((cnt > 0) ? 1 : -1);
  193.   register int lim0;
  194.   unsigned char *base;
  195.   register unsigned char *cursor, *limit;
  196.  
  197.   if (shortage != 0)
  198.     *shortage = 0;
  199.  
  200.   immediate_quit = 1;
  201.  
  202.   if (cnt > 0)
  203.     while (pos != lim + 1)
  204.       {
  205.     lim0 =  BufferSafeCeiling (pos);
  206.     lim0 = min (lim, lim0);
  207.     limit = &FETCH_CHAR (lim0) + 1;
  208.     base = (cursor = &FETCH_CHAR (pos));
  209.     while (1)
  210.       {
  211.         while (*cursor != target && ++cursor != limit)
  212.           ;
  213.         if (cursor != limit)
  214.           {
  215.         if (--cnt == 0)
  216.           {
  217.             immediate_quit = 0;
  218.             return (pos + cursor - base + 1);
  219.           }
  220.         else
  221.           if (++cursor == limit)
  222.             break;
  223.           }
  224.         else
  225.           break;
  226.       }
  227.     pos += cursor - base;
  228.       }
  229.   else
  230.     {
  231.       pos--;            /* first character we scan */
  232.       while (pos > lim - 1)
  233.     {            /* we WILL scan under pos */
  234.       lim0 =  BufferSafeFloor (pos);
  235.       lim0 = max (lim, lim0);
  236.       limit = &FETCH_CHAR (lim0) - 1;
  237.       base = (cursor = &FETCH_CHAR (pos));
  238.       cursor++;
  239.       while (1)
  240.         {
  241.           while (--cursor != limit && *cursor != target)
  242.         ;
  243.           if (cursor != limit)
  244.         {
  245.           if (++cnt == 0)
  246.             {
  247.               immediate_quit = 0;
  248.               return (pos + cursor - base + 1);
  249.             }
  250.         }
  251.           else
  252.         break;
  253.         }
  254.       pos += cursor - base;
  255.     }
  256.     }
  257.   immediate_quit = 0;
  258.   if (shortage != 0)
  259.     *shortage = cnt * direction;
  260.   return (pos + ((direction == 1 ? 0 : 1)));
  261. }
  262.  
  263. int
  264. find_next_newline (from, cnt)
  265.      register int from, cnt;
  266. {
  267.   return (scan_buffer (NEWLINE, from, cnt, (int *) 0));
  268. }
  269.  
  270. DEFUN ("skip-chars-forward", Fskip_chars_forward, Sskip_chars_forward, 1, 2, 0,
  271.   "Move point forward, stopping before a char not in CHARS, or at position LIM.\n\
  272. CHARS is like the inside of a [...] in a regular expression\n\
  273. except that ] is never special and \\ quotes ^, - or \\.\n\
  274. Thus, with arg \"a-zA-Z\", this skips letters stopping before first nonletter.\n\
  275. With arg \"^a-zA-Z\", skips nonletters stopping before first letter.")
  276.   (string, lim)
  277.      Lisp_Object string, lim;
  278. {
  279.   skip_chars (1, string, lim);
  280.   return Qnil;
  281. }
  282.  
  283. DEFUN ("skip-chars-backward", Fskip_chars_backward, Sskip_chars_backward, 1, 2, 0,
  284.   "Move point backward, stopping after a char not in CHARS, or at position LIM.\n\
  285. See skip-chars-forward for details.")
  286.   (string, lim)
  287.      Lisp_Object string, lim;
  288. {
  289.   skip_chars (0, string, lim);
  290.   return Qnil;
  291. }
  292.  
  293. skip_chars (forwardp, string, lim)
  294.      int forwardp;
  295.      Lisp_Object string, lim;
  296. {
  297.   register unsigned char *p, *pend;
  298.   register unsigned char c;
  299.   unsigned char fastmap[0400];
  300.   int negate = 0;
  301.   register int i;
  302.  
  303.   CHECK_STRING (string, 0);
  304.  
  305.   if (NULL (lim))
  306.     XFASTINT (lim) = forwardp ? ZV : BEGV;
  307.   else
  308.     CHECK_NUMBER_COERCE_MARKER (lim, 1);
  309.  
  310.   /* In any case, don't allow scan outside bounds of buffer.  */
  311.   if (XFASTINT (lim) > ZV)
  312.     XFASTINT (lim) = ZV;
  313.   if (XFASTINT (lim) < BEGV)
  314.     XFASTINT (lim) = BEGV;
  315.  
  316.   p = XSTRING (string)->data;
  317.   pend = p + XSTRING (string)->size;
  318.   bzero (fastmap, sizeof fastmap);
  319.  
  320.   if (p != pend && *p == '^')
  321.     {
  322.       negate = 1; p++;
  323.     }
  324.  
  325.   /* Find the characters specified and set their elements of fastmap.  */
  326.  
  327.   while (p != pend)
  328.     {
  329.       c = *p++;
  330.       if (c == '\\')
  331.         {
  332.       if (p == pend) break;
  333.       c = *p++;
  334.     }
  335.       if (p != pend && *p == '-')
  336.     {
  337.       p++;
  338.       if (p == pend) break;
  339.       while (c <= *p)
  340.         {
  341.           fastmap[c] = 1;
  342.           c++;
  343.         }
  344.       p++;
  345.     }
  346.       else
  347.     fastmap[c] = 1;
  348.     }
  349.  
  350.   /* If ^ was the first character, complement the fastmap. */
  351.  
  352.   if (negate)
  353.     for (i = 0; i < sizeof fastmap; i++)
  354.       fastmap[i] ^= 1;
  355.  
  356.   immediate_quit = 1;
  357.   if (forwardp)
  358.     {
  359.       while (point < XINT (lim) && fastmap[FETCH_CHAR (point)])
  360.     SET_PT (point + 1);
  361.     }
  362.   else
  363.     {
  364.       while (point > XINT (lim) && fastmap[FETCH_CHAR (point - 1)])
  365.     SET_PT (point - 1);
  366.     }
  367.   immediate_quit = 0;
  368. }
  369.  
  370. /* Subroutines of Lisp buffer search functions. */
  371.  
  372. static Lisp_Object
  373. search_command (string, bound, noerror, count, direction, RE)
  374.      Lisp_Object string, bound, noerror, count;
  375.      int direction;
  376.      int RE;
  377. {
  378.   register int np;
  379.   int lim;
  380.   int n = direction;
  381.  
  382.   if (!NULL (count))
  383.     {
  384.       CHECK_NUMBER (count, 3);
  385.       n *= XINT (count);
  386.     }
  387.  
  388.   CHECK_STRING (string, 0);
  389.   if (NULL (bound))
  390.     lim = n > 0 ? ZV : BEGV;
  391.   else
  392.     {
  393.       CHECK_NUMBER_COERCE_MARKER (bound, 1);
  394.       lim = XINT (bound);
  395.       if (n > 0 ? lim < point : lim > point)
  396.     error ("Invalid search bound (wrong side of point)");
  397.       if (lim > ZV)
  398.     lim = ZV;
  399.       if (lim < BEGV)
  400.     lim = BEGV;
  401.     }
  402.  
  403.   np = search_buffer (string, point, lim, n, RE);
  404.   if (np <= 0)
  405.     {
  406.       if (NULL (noerror))
  407.     return signal_failure (string);
  408.       if (!EQ (noerror, Qt))
  409.     {
  410.       if (lim < BEGV || lim > ZV)
  411.         abort ();
  412.       SET_PT (lim);
  413.     }
  414.       return Qnil;
  415.     }
  416.  
  417.   if (np < BEGV || np > ZV)
  418.     abort ();
  419.  
  420.   SET_PT (np);
  421.  
  422.   return Qt;
  423. }
  424.  
  425. /* search for the n'th occurrence of `string' in the current buffer,
  426.    starting at position `from' and stopping at position `lim',
  427.    treating `pat' as a literal string if `RE' is false or as
  428.    a regular expression if `RE' is true.
  429.  
  430.    If `n' is positive, searching is forward and `lim' must be greater than `from'.
  431.    If `n' is negative, searching is backward and `lim' must be less than `from'.
  432.  
  433.    Returns -x if only `n'-x occurrences found (x > 0),
  434.    or else the position at the beginning of the `n'th occurrence (if searching backward)
  435.    or the end (if searching forward).  */
  436.  
  437. /* INTERFACE CHANGE ALERT!!!!  search_buffer now returns -x if only */
  438. /* n-x occurences are found. */
  439.  
  440. search_buffer (string, pos, lim, n, RE)
  441.      Lisp_Object string;
  442.      int pos;
  443.      int lim;
  444.      int n;
  445.      int RE;
  446. {
  447.   struct Lisp_Sorttab *sorttab;
  448.   register char_t *trt; /* Equivalence class table. */
  449.   int len = XSTRING (string)->size;
  450.   unsigned char *base_pat = XSTRING (string)->data;
  451.   register int *BM_tab;
  452.   int *BM_tab_base;
  453.   register int direction = ((n > 0) ? 1 : -1);
  454.   register int dirlen;
  455.   int infinity, limit, k, stride_for_teases;
  456.   register unsigned char *pat, *cursor, *p_limit;  
  457.   register int i, j;
  458.   unsigned char *p1, *p2;
  459.   int s1, s2;
  460.  
  461.  
  462.   if (!len)
  463.     return (0);
  464.  
  465.   sorttab = current_sort_table ();
  466.   trt = current_equiv_class_table ();
  467.   if (RE)
  468.     compile_pattern (string, &searchbuf, sorttab);
  469.   
  470.   if (RE            /* Here we detect whether the */
  471.                 /* generality of an RE search is */
  472.                 /* really needed. */
  473.       && *(searchbuf.buffer) == (char) exactn /* first item is "exact match" */
  474.       && searchbuf.buffer[1] + 2 == searchbuf.used) /*first is ONLY item */
  475.     {
  476.       RE = 0;            /* can do straight (non RE) search */
  477.       pat = (base_pat = (unsigned char *) searchbuf.buffer + 2);
  478.                 /* sorttab already applied */
  479.       len = searchbuf.used - 2;
  480.     }
  481.   else if (!RE)
  482.     {
  483.       pat = (unsigned char *) alloca (len);
  484.  
  485.       /* Copy the pattern; apply sorttab -- XXXX: Sorttab??? */
  486.       for (i = len; i--;)
  487.     *pat++ = (trt ? trt [*base_pat++] : *base_pat++);
  488.       pat -= len; base_pat = pat;
  489.     }
  490.  
  491.   if (RE)
  492.     {
  493.       immediate_quit = 1;    /* Quit immediately if user types ^G,
  494.                    because letting this function finish
  495.                    can take too long. */
  496.       QUIT;            /* Do a pending quit right away,
  497.                    to avoid paradoxical behavior */
  498.       /* Get pointers and sizes of the two strings
  499.      that make up the visible portion of the buffer. */
  500.  
  501.       p1 = BEGV_ADDR;
  502.       s1 = GPT - BEGV;
  503.       p2 = GAP_END_ADDR;
  504.       s2 = ZV - GPT;
  505.       if (s1 < 0)
  506.     {
  507.       p2 = p1;
  508.       s2 = ZV - BEGV;
  509.       s1 = 0;
  510.     }
  511.       if (s2 < 0)
  512.     {
  513.       s1 = ZV - BEGV;
  514.       s2 = 0;
  515.     }
  516.       while (n < 0)
  517.     {
  518.       if (re_search_2 (&searchbuf, p1, s1, p2, s2,
  519.                pos - BEGV, lim - pos, &search_regs,
  520.                /* Don't allow match past current point */
  521.                pos - BEGV)
  522.           >= 0)
  523.         {
  524.           j = BEGV;
  525.           for (i = 0; i < RE_NREGS; i++)
  526.         if (search_regs.start[i] >= 0)
  527.           {
  528.             search_regs.start[i] += j;
  529.             search_regs.end[i] += j;
  530.           }
  531.           /* Set pos to the new position. */
  532.           pos = search_regs.start[0];
  533.         }
  534.       else
  535.         {
  536.           immediate_quit = 0;
  537.           return (n);
  538.         }
  539.       n++;
  540.     }
  541.       while (n > 0)
  542.     {
  543.       if (re_search_2 (&searchbuf, p1, s1, p2, s2,
  544.                pos - BEGV, lim - pos, &search_regs,
  545.                lim - BEGV)
  546.           >= 0)
  547.         {
  548.           j = BEGV;
  549.           for (i = 0; i < RE_NREGS; i++)
  550.         if (search_regs.start[i] >= 0)
  551.           {
  552.             search_regs.start[i] += j;
  553.             search_regs.end[i] += j;
  554.           }
  555.           pos = search_regs.end[0];
  556.         }
  557.       else
  558.         {
  559.           immediate_quit = 0;
  560.           return (0 - n);
  561.         }
  562.       n--;
  563.     }
  564.       immediate_quit = 0;
  565.       return (pos);
  566.     }
  567.   else                /* non-RE case */
  568.     {
  569. #ifdef C_ALLOCA
  570.       int BM_tab_space[0400];
  571.       BM_tab = &BM_tab_space[0];
  572. #else
  573.       BM_tab = (int *) alloca (0400 * sizeof (int));
  574. #endif
  575.       /* The general approach is that we are going to maintain that we know */
  576.       /* the first (closest to the present position, in whatever direction */
  577.       /* we're searching) character that could possibly be the last */
  578.       /* (furthest from present position) character of a valid match.  We */
  579.       /* advance the state of our knowledge by looking at that character */
  580.       /* and seeing whether it indeed matches the last character of the */
  581.       /* pattern.  If it does, we take a closer look.  If it does not, we */
  582.       /* move our pointer (to putative last characters) as far as is */
  583.       /* logically possible.  This amount of movement, which I call a */
  584.       /* stride, will be the length of the pattern if the actual character */
  585.       /* appears nowhere in the pattern, otherwise it will be the distance */
  586.       /* from the last occurrence of that character to the end of the */
  587.       /* pattern. */
  588.       /* As a coding trick, an enormous stride is coded into the table for */
  589.       /* characters that match the last character.  This allows use of only */
  590.       /* a single test, a test for having gone past the end of the */
  591.       /* permissible match region, to test for both possible matches (when */
  592.       /* the stride goes past the end immediately) and failure to */
  593.       /* match (where you get nudged past the end one stride at a time). */ 
  594.  
  595.       /* Here we make a "mickey mouse" BM table.  The stride of the search */
  596.       /* is determined only by the last character of the putative match. */
  597.       /* If that character does not match, we will stride the proper */
  598.       /* distance to propose a match that superimposes it on the last */
  599.       /* instance of a character that matches it (per sorttab), or misses */
  600.       /* it entirely if there is none. */  
  601.  
  602.       dirlen = len * direction;
  603.       infinity = dirlen - (lim + pos + len + len) * direction;
  604.       if (direction < 0)
  605.     pat = (base_pat += len - 1);
  606.       BM_tab_base = BM_tab;
  607.       BM_tab += 0400;
  608.       j = dirlen;        /* to get it in a register */
  609.       /* A character that does not appear in the pattern induces a */
  610.       /* stride equal to the pattern length. */
  611.       while (BM_tab_base != BM_tab)
  612.     {
  613.       *--BM_tab = j;
  614.       *--BM_tab = j;
  615.       *--BM_tab = j;
  616.       *--BM_tab = j;
  617.     }
  618.       i = 0;
  619.       while (i != infinity)
  620.     {
  621.       j = pat[i]; i += direction;
  622.       if (i == dirlen) i = infinity;
  623.       if (sorttab == NULL_SORT_TABLE)
  624.         {
  625.           if (i == infinity)
  626.         stride_for_teases = BM_tab[j];
  627.           BM_tab[j] = dirlen - i;
  628.         }
  629.       else
  630.         {
  631.           /* We now want to set BM_tab[x] = dirlen - 1 for
  632.          all characters x in equivalence class j. */
  633.           k = sorttab->srt_dope[j].ec_lo;
  634.           if (i == infinity)
  635.         stride_for_teases = BM_tab[sorttab->srt_chars[k]];
  636.           do
  637.             BM_tab[sorttab->srt_chars[k++]] = dirlen - i;
  638.           while (k <= sorttab->srt_dope[j].ec_hi);
  639.         }
  640.       /* stride_for_teases tells how much to stride if we get a */
  641.       /* match on the far character but are subsequently */
  642.       /* disappointed, by recording what the stride would have been */
  643.       /* for that character if the last character had been */
  644.       /* different. */
  645.     }
  646.       infinity = dirlen - infinity;
  647.       pos += dirlen - ((direction > 0) ? direction : 0);
  648.       /* loop invariant - pos points at where last char (first char if reverse)
  649.      of pattern would align in a possible match.  */
  650.       while (n != 0)
  651.     {
  652.       if ((lim - pos - (direction > 0)) * direction < 0)
  653.         return (n * (0 - direction));
  654.       /* First we do the part we can by pointers (maybe nothing) */
  655.       QUIT;
  656.       pat = base_pat;
  657.       limit = pos - dirlen + direction;
  658.       limit = ((direction > 0)
  659.            ? BufferSafeCeiling (limit)
  660.            : BufferSafeFloor (limit));
  661.       /* LIMIT is now the last (not beyond-last!) value
  662.          POS can take on without hitting edge of buffer or the gap.  */
  663.       limit = ((direction > 0)
  664.            ? min (lim - 1, min (limit, pos + 20000))
  665.            : max (lim, max (limit, pos - 20000)));
  666.       if ((limit - pos) * direction > 20)
  667.         {
  668.           p_limit = &FETCH_CHAR (limit);
  669.           p2 = (cursor = &FETCH_CHAR (pos));
  670.           /* In this loop, pos + cursor - p2 is the surrogate for pos */
  671.           while (1)        /* use one cursor setting as long as i can */
  672.         {
  673.           if (direction > 0) /* worth duplicating */
  674.             {
  675.               /* Use signed comparison if appropriate
  676.              to make cursor+infinity sure to be > p_limit.
  677.              Assuming that the buffer lies in a range of addresses
  678.              that are all "positive" (as ints) or all "negative",
  679.              either kind of comparison will work as long
  680.              as we don't step by infinity.  So pick the kind
  681.              that works when we do step by infinity.  */
  682.               if ((int) (p_limit + infinity) > (int) p_limit)
  683.             while ((int) cursor <= (int) p_limit)
  684.               cursor += BM_tab[*cursor];
  685.               else
  686.             while ((unsigned int) cursor <= (unsigned int) p_limit)
  687.               cursor += BM_tab[*cursor];
  688.             }
  689.           else
  690.             {
  691.               if ((int) (p_limit + infinity) < (int) p_limit)
  692.             while ((int) cursor >= (int) p_limit)
  693.               cursor += BM_tab[*cursor];
  694.               else
  695.             while ((unsigned int) cursor >= (unsigned int) p_limit)
  696.               cursor += BM_tab[*cursor];
  697.             }
  698. /* If you are here, cursor is beyond the end of the searched region. */
  699.  /* This can happen if you match on the far character of the pattern, */
  700.  /* because the "stride" of that character is infinity, a number able */
  701.  /* to throw you well beyond the end of the search.  It can also */
  702.  /* happen if you fail to match within the permitted region and would */
  703.  /* otherwise try a character beyond that region */
  704.           if ((cursor - p_limit) * direction <= len)
  705.             break;    /* a small overrun is genuine */
  706.           cursor -= infinity; /* large overrun = hit */
  707.           i = dirlen - direction;
  708.           if (trt)
  709.             {
  710.               while ((i -= direction) + direction != 0)
  711.             if (pat[i] != trt[*(cursor -= direction)])
  712.               break;
  713.             }
  714.           else
  715.             {
  716.               while ((i -= direction) + direction != 0)
  717.             if (pat[i] != *(cursor -= direction))
  718.               break;
  719.             }
  720.           cursor += dirlen - i - direction;    /* fix cursor */
  721.           if (i + direction == 0)
  722.             {
  723.               cursor -= direction;
  724.               search_regs.start[0]
  725.             = pos + cursor - p2 + ((direction > 0)
  726.                            ? 1 - len : 0);
  727.               search_regs.end[0] = len + search_regs.start[0];
  728.               if ((n -= direction) != 0)
  729.             cursor += dirlen; /* to resume search */
  730.               else
  731.             return ((direction > 0)
  732.                 ? search_regs.end[0] : search_regs.start[0]);
  733.             }
  734.           else
  735.             cursor += stride_for_teases; /* <sigh> we lose -  */
  736.         }
  737.           pos += cursor - p2;
  738.         }
  739.       else
  740.         /* Now we'll pick up a clump that has to be done the hard */
  741.         /* way because it covers a discontinuity */
  742.         {
  743.           limit = ((direction > 0)
  744.                ? BufferSafeCeiling (pos - dirlen + 1)
  745.                : BufferSafeFloor (pos - dirlen - 1));
  746.           limit = ((direction > 0)
  747.                ? min (limit + len, lim - 1)
  748.                : max (limit - len, lim));
  749.           /* LIMIT is now the last value POS can have
  750.          and still be valid for a possible match.  */
  751.           while (1)
  752.         {
  753.           /* This loop can be coded for space rather than */
  754.           /* speed because it will usually run only once. */
  755.           /* (the reach is at most len + 21, and typically */
  756.           /* does not exceed len) */    
  757.           while ((limit - pos) * direction >= 0)
  758.             pos += BM_tab[FETCH_CHAR(pos)];
  759.           /* now run the same tests to distinguish going off the */
  760.           /* end, a match or a phoney match. */
  761.           if ((pos - limit) * direction <= len)
  762.             break;    /* ran off the end */
  763.           /* Found what might be a match.
  764.              Set POS back to last (first if reverse) char pos.  */
  765.           pos -= infinity;
  766.           i = dirlen - direction;
  767.           while ((i -= direction) + direction != 0)
  768.             {
  769.               pos -= direction;
  770.               if (pat[i] != (trt
  771.                      ? trt[FETCH_CHAR(pos)]
  772.                      : FETCH_CHAR (pos)))
  773.             break;
  774.             }
  775.           /* Above loop has moved POS part or all the way
  776.              back to the first char pos (last char pos if reverse).
  777.              Set it once again at the last (first if reverse) char.  */
  778.           pos += dirlen - i- direction;
  779.           if (i + direction == 0)
  780.             {
  781.               pos -= direction;
  782.               search_regs.start[0]
  783.             = pos + ((direction > 0) ? 1 - len : 0);
  784.               search_regs.end[0] = len + search_regs.start[0];
  785.               if ((n -= direction) != 0)
  786.             pos += dirlen; /* to resume search */
  787.               else
  788.             return ((direction > 0)
  789.                 ? search_regs.end[0] : search_regs.start[0]);
  790.             }
  791.           else
  792.             pos += stride_for_teases;
  793.         }
  794.           }
  795.       /* We have done one clump.  Can we continue? */
  796.       if ((lim - pos) * direction < 0)
  797.         return ((0 - n) * direction);
  798.     }
  799.       return pos;
  800.     }
  801. }
  802.  
  803. /* Given a string of words separated by word delimiters,
  804.   compute a regexp that matches those exact words
  805.   separated by arbitrary punctuation.  */
  806.  
  807. static Lisp_Object
  808. wordify (string)
  809.      Lisp_Object string;
  810. {
  811.   register unsigned char *p, *o;
  812.   register int i, len, punct_count = 0, word_count = 0;
  813.   Lisp_Object val;
  814.  
  815.   CHECK_STRING (string, 0);
  816.   p = XSTRING (string)->data;
  817.   len = XSTRING (string)->size;
  818.  
  819.   for (i = 0; i < len; i++)
  820.     if (SYNTAX (p[i]) != Sword)
  821.       {
  822.     punct_count++;
  823.     if (i > 0 && SYNTAX (p[i-1]) == Sword) word_count++;
  824.       }
  825.   if (SYNTAX (p[len-1]) == Sword) word_count++;
  826.   if (!word_count) return build_string ("");
  827.  
  828.   val = make_string (p, len - punct_count + 5 * (word_count - 1) + 4);
  829.  
  830.   o = XSTRING (val)->data;
  831.   *o++ = '\\';
  832.   *o++ = 'b';
  833.  
  834.   for (i = 0; i < len; i++)
  835.     if (SYNTAX (p[i]) == Sword)
  836.       *o++ = p[i];
  837.     else if (i > 0 && SYNTAX (p[i-1]) == Sword && --word_count)
  838.       {
  839.     *o++ = '\\';
  840.     *o++ = 'W';
  841.     *o++ = '\\';
  842.     *o++ = 'W';
  843.     *o++ = '*';
  844.       }
  845.  
  846.   *o++ = '\\';
  847.   *o++ = 'b';
  848.  
  849.   return val;
  850. }
  851.  
  852. DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4,
  853.   "sSearch backward: ",
  854.   "Search backward from point for STRING.\n\
  855. Set point to the beginning of the occurrence found, and return t.\n\
  856. An optional second argument bounds the search; it is a buffer position.\n\
  857. The match found must not extend before that position.\n\
  858. Optional third argument, if t, means if fail just return nil (no error).\n\
  859.  If not nil and not t, position at limit of search and return nil.\n\
  860. Optional fourth argument is repeat count--search for successive occurrences.")
  861.   (string, bound, noerror, count)
  862.      Lisp_Object string, bound, noerror, count;
  863. {
  864.   return search_command (string, bound, noerror, count, -1, 0);
  865. }
  866.  
  867. DEFUN ("search-forward", Fsearch_forward, Ssearch_forward, 1, 4, "sSearch: ",
  868.   "Search forward from point for STRING.\n\
  869. Set point to the end of the occurrence found, and return t.\n\
  870. An optional second argument bounds the search; it is a buffer position.\n\
  871. The match found must not extend after that position.\n\
  872. Optional third argument, if t, means if fail just return nil (no error).\n\
  873.   If not nil and not t, move to limit of search and return nil.\n\
  874. Optional fourth argument is repeat count--search for successive occurrences.")
  875.   (string, bound, noerror, count)
  876.      Lisp_Object string, bound, noerror, count;
  877. {
  878.   return search_command (string, bound, noerror, count, 1, 0);
  879. }
  880.  
  881. DEFUN ("word-search-backward", Fword_search_backward, Sword_search_backward, 1, 4,
  882.   "sWord search backward: ",
  883.   "Search backward from point for STRING, ignoring differences in punctuation.\n\
  884. Set point to the beginning of the occurrence found, and return t.\n\
  885. An optional second argument bounds the search; it is a buffer position.\n\
  886. The match found must not extend before that position.\n\
  887. Optional third argument, if t, means if fail just return nil (no error).\n\
  888.   If not nil and not t, move to limit of search and return nil.\n\
  889. Optional fourth argument is repeat count--search for successive occurrences.")
  890.   (string, bound, noerror, count)
  891.      Lisp_Object string, bound, noerror, count;
  892. {
  893.   return search_command (wordify (string), bound, noerror, count, -1, 1);
  894. }
  895.  
  896. DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4,
  897.   "sWord search: ",
  898.   "Search forward from point for STRING, ignoring differences in punctuation.\n\
  899. Set point to the end of the occurrence found, and return t.\n\
  900. An optional second argument bounds the search; it is a buffer position.\n\
  901. The match found must not extend after that position.\n\
  902. Optional third argument, if t, means if fail just return nil (no error).\n\
  903.   If not nil and not t, move to limit of search and return nil.\n\
  904. Optional fourth argument is repeat count--search for successive occurrences.")
  905.   (string, bound, noerror, count)
  906.      Lisp_Object string, bound, noerror, count;
  907. {
  908.   return search_command (wordify (string), bound, noerror, count, 1, 1);
  909. }
  910.  
  911. DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4,
  912.   "sRE search backward: ",
  913.   "Search backward from point for match for regular expression REGEXP.\n\
  914. Set point to the beginning of the match, and return t.\n\
  915. The match found is the one starting last in the buffer\n\
  916. and yet ending before the place the origin of the search.\n\
  917. An optional second argument bounds the search; it is a buffer position.\n\
  918. The match found must start at or after that position.\n\
  919. Optional third argument, if t, means if fail just return nil (no error).\n\
  920.   If not nil and not t, move to limit of search and return nil.\n\
  921. Optional fourth argument is repeat count--search for successive occurrences.\n\
  922. See also the functions match-beginning and match-end and replace-match.")
  923.   (string, bound, noerror, count)
  924.      Lisp_Object string, bound, noerror, count;
  925. {
  926.   return search_command (string, bound, noerror, count, -1, 1);
  927. }
  928.  
  929. DEFUN ("re-search-forward", Fre_search_forward, Sre_search_forward, 1, 4,
  930.   "sRE search: ",
  931.   "Search forward from point for regular expression REGEXP.\n\
  932. Set point to the end of the occurrence found, and return t.\n\
  933. An optional second argument bounds the search; it is a buffer position.\n\
  934. The match found must not extend after that position.\n\
  935. Optional third argument, if t, means if fail just return nil (no error).\n\
  936.   If not nil and not t, move to limit of search and return nil.\n\
  937. Optional fourth argument is repeat count--search for successive occurrences.\n\
  938. See also the functions match-beginning and match-end and replace-match.")
  939.   (string, bound, noerror, count)
  940.      Lisp_Object string, bound, noerror, count;
  941. {
  942.   return search_command (string, bound, noerror, count, 1, 1);
  943. }
  944.  
  945. DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 3, 0,
  946.   "Replace text matched by last search with NEWTEXT.\n\
  947. If second arg FIXEDCASE is non-nil, do not alter case of replacement text.\n\
  948. Otherwise convert to all caps or cap initials, like replaced text.\n\
  949. If third arg LITERAL is non-nil, insert NEWTEXT literally.\n\
  950. Otherwise treat \\ as special:\n\
  951.   \\& in NEWTEXT means substitute original matched text,\n\
  952.   \\N means substitute match for \\(...\\) number N,\n\
  953.   \\\\ means insert one \\.\n\
  954. Leaves point at end of replacement text.")
  955.   (string, fixedcase, literal)
  956.      Lisp_Object string, fixedcase, literal;
  957. {
  958.   enum { nochange, all_caps, cap_initial } case_action;
  959.   register int pos, last;
  960.   int some_multiletter_word;
  961.   int some_letter = 0;
  962.   register int c, prevc;
  963.   int inslen;
  964.  
  965.   CHECK_STRING (string, 0);
  966.  
  967.   case_action = nochange;    /* We tried an initialization */
  968.                 /* but some C compilers blew it */
  969.   if (search_regs.start[0] < BEGV
  970.       || search_regs.start[0] > search_regs.end[0]
  971.       || search_regs.end[0] > ZV)
  972.     args_out_of_range(make_number (search_regs.start[0]),
  973.               make_number (search_regs.end[0]));
  974.  
  975.   if (NULL (fixedcase))
  976.     {
  977.       /* Decide how to casify by examining the matched text. */
  978.  
  979.       last = search_regs.end[0];
  980.       prevc = NEWLINE;
  981.       case_action = all_caps;
  982.  
  983.       /* some_multiletter_word is set nonzero if any original word
  984.      is more than one letter long. */
  985.       some_multiletter_word = 0;
  986.  
  987.       for (pos = search_regs.start[0]; pos < last; pos++)
  988.     {
  989.       c = FETCH_CHAR (pos);
  990.       switch (LOCAL_CASE (c))
  991.         {
  992.         case lowercase_e:
  993.           /* Cannot be all caps if any original char is lower case */
  994.           case_action = cap_initial;
  995.           if (SYNTAX (prevc) != Sword)
  996.         {
  997.           /* Cannot even be cap initials
  998.              if some original initial is lower case */
  999.           case_action = nochange;
  1000.           break;
  1001.         }
  1002.           else
  1003.         some_multiletter_word = 1;
  1004.           break;
  1005.         case uppercase_e:
  1006.           some_letter = 1;
  1007.           if (!some_multiletter_word && SYNTAX (prevc) == Sword)
  1008.         some_multiletter_word = 1;
  1009.           break;
  1010.         }
  1011.       prevc = c;
  1012.     }
  1013.  
  1014.       /* Do not make new text all caps
  1015.      if the original text contained only single letter words. */
  1016.       if (case_action == all_caps && !some_multiletter_word)
  1017.     case_action = cap_initial;
  1018.  
  1019.       if (!some_letter) case_action = nochange;
  1020.     }
  1021.  
  1022.   SET_PT (search_regs.end[0]);
  1023.   if (!NULL (literal))
  1024.     Finsert (1, &string);
  1025.   else
  1026.     {
  1027.       struct gcpro gcpro1;
  1028.       GCPRO1 (string);
  1029.       for (pos = 0; pos < XSTRING (string)->size; pos++)
  1030.     {
  1031.       c = XSTRING (string)->data[pos];
  1032.       if (c == '\\')
  1033.         {
  1034.           c = XSTRING (string)->data[++pos];
  1035.           if (c == '&')
  1036.         Finsert_buffer_substring (Fcurrent_buffer (),
  1037.                       make_number (search_regs.start[0]),
  1038.                       make_number (search_regs.end[0]));
  1039.           else if (c >= '1' && c <= RE_NREGS + '0')
  1040.         {
  1041.           if (search_regs.start[c - '0'] >= 1)
  1042.             Finsert_buffer_substring (Fcurrent_buffer (),
  1043.                           make_number (search_regs.start[c - '0']),
  1044.                           make_number (search_regs.end[c - '0']));
  1045.         }
  1046.           else
  1047.         insert_char (c);
  1048.         }
  1049.       else
  1050.         insert_char (c);
  1051.     }
  1052.       UNGCPRO;
  1053.     }
  1054.  
  1055.   inslen = point - (search_regs.end[0]);
  1056.   del_range (search_regs.start[0], search_regs.end[0]);
  1057.  
  1058.   if (case_action == all_caps)
  1059.     Fupcase_region (make_number (point - inslen), make_number (point));
  1060.   else if (case_action == cap_initial)
  1061.     upcase_initials_region (make_number (point - inslen), make_number (point));
  1062.   return Qnil;
  1063. }
  1064.  
  1065. static Lisp_Object
  1066. match_limit (num, beginningp)
  1067.      Lisp_Object num;
  1068.      int beginningp;
  1069. {
  1070.   register int n;
  1071.  
  1072.   CHECK_NUMBER (num, 0);
  1073.   n = XINT (num);
  1074.   if (n < 0 || n >= RE_NREGS)
  1075.     args_out_of_range (num, make_number (RE_NREGS));
  1076.   if (search_regs.start[n] < 0)
  1077.     return Qnil;
  1078.   return (make_number ((beginningp) ? search_regs.start[n]
  1079.                             : search_regs.end[n]));
  1080. }
  1081.  
  1082. DEFUN ("match-beginning", Fmatch_beginning, Smatch_beginning, 1, 1, 0,
  1083.   "Return the character number of start of text matched by last regexp searched for.\n\
  1084. ARG, a number, specifies which parenthesized expression in the last regexp.\n\
  1085.  Value is nil if ARGth pair didn't match, or there were less than ARG pairs.\n\
  1086. Zero means the entire text matched by the whole regexp.")
  1087.   (num)
  1088.      Lisp_Object num;
  1089. {
  1090.   return match_limit (num, 1);
  1091. }
  1092.  
  1093. DEFUN ("match-end", Fmatch_end, Smatch_end, 1, 1, 0,
  1094.   "Return the character number of end of text matched by last regexp searched for.\n\
  1095. ARG, a number, specifies which parenthesized expression in the last regexp.\n\
  1096.  Value is nil if ARGth pair didn't match, or there were less than ARG pairs.\n\
  1097. Zero means the entire text matched by the whole regexp.")
  1098.   (num)
  1099.      Lisp_Object num;
  1100. {
  1101.   return match_limit (num, 0);
  1102.  
  1103. DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 0, 0,
  1104.   "Return list containing all info on what the last search matched.\n\
  1105. Element 2N is (match-beginning N); element 2N + 1 is (match-end N).\n\
  1106. All the elements are normally markers, or nil if the Nth pair didn't match.\n\
  1107. 0 is also possible, when matching was done with `string-match',\n\
  1108. if a match began at index 0 in the string.")
  1109.   ()
  1110. {
  1111.   Lisp_Object data[2 * RE_NREGS];
  1112.   int i, len;
  1113.  
  1114.   len = -1;
  1115.   for (i = 0; i < RE_NREGS; i++)
  1116.     {
  1117.       int start = search_regs.start[i];
  1118.       if (start >= 0)
  1119.     {
  1120.       if (start == 0)
  1121.         data[2 * i] = 0;
  1122.       else
  1123.         {
  1124.           data[2 * i] = Fmake_marker ();
  1125.           Fset_marker (data[2 * i], make_number (start), Qnil);
  1126.         }
  1127.  
  1128.       if (search_regs.end[i] == 0)
  1129.         data[2 * i + 1] = 0;
  1130.       else
  1131.         {
  1132.           data[2 * i + 1] = Fmake_marker ();
  1133.           Fset_marker (data[2 * i + 1],
  1134.                make_number (search_regs.end[i]), Qnil);
  1135.         }
  1136.       len = i;
  1137.     }
  1138.       else
  1139.     data[2 * i] = data [2 * i + 1] = Qnil;
  1140.     }
  1141.   return Flist (2 * len + 2, data);
  1142. }
  1143.  
  1144.  
  1145. DEFUN ("store-match-data", Fstore_match_data, Sstore_match_data, 1, 1, 0,
  1146.   "Set internal data on last search match from elements of LIST.\n\
  1147. LIST should have been created by calling match-data previously.")
  1148.   (list)
  1149.      register Lisp_Object list;
  1150. {
  1151.   register int i;
  1152.   register Lisp_Object marker;
  1153.  
  1154.   if (!CONSP (list) && !NULL (list))
  1155.     list = wrong_type_argument (Qconsp, list, 0);
  1156.  
  1157.   for (i = 0; i < RE_NREGS; i++)
  1158.     {
  1159.       marker = Fcar (list);
  1160.       if (NULL (marker))
  1161.     {
  1162.       search_regs.start[i] = -1;
  1163.       list = Fcdr (list);
  1164.     }
  1165.       else
  1166.     {
  1167.       if (XTYPE (marker) == Lisp_Marker
  1168.           && XMARKER (marker)->buffer == 0)
  1169.         XFASTINT (marker) = 0;
  1170.  
  1171.       CHECK_NUMBER_COERCE_MARKER (marker, 0);
  1172.       search_regs.start[i] = XINT (marker);
  1173.       list = Fcdr (list);
  1174.  
  1175.       marker = Fcar (list);
  1176.       if (XTYPE (marker) == Lisp_Marker
  1177.           && XMARKER (marker)->buffer == 0)
  1178.         XFASTINT (marker) = 0;
  1179.  
  1180.       CHECK_NUMBER_COERCE_MARKER (marker, 0);
  1181.       search_regs.end[i] = XINT (marker);
  1182.     }
  1183.       list = Fcdr (list);
  1184.     }
  1185.  
  1186.   return Qnil;  
  1187. }
  1188.  
  1189. /* Quote a string to inactivate reg-expr chars */
  1190.  
  1191. DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0,
  1192.   "Return a regexp string which matches exactly STRING and nothing else.")
  1193.   (str)
  1194.      Lisp_Object str;
  1195. {
  1196.   register unsigned char *in, *out, *end;
  1197.   register unsigned char *temp;
  1198.  
  1199.   CHECK_STRING (str, 0);
  1200.  
  1201.   temp = (unsigned char *) alloca (XSTRING (str)->size * 2);
  1202.  
  1203.   /* Now copy the data into the new string, inserting escapes. */
  1204.  
  1205.   in = XSTRING (str)->data;
  1206.   end = in + XSTRING (str)->size;
  1207.   out = temp; 
  1208.  
  1209.   for (; in != end; in++)
  1210.     {
  1211.       if (*in == '[' || *in == ']'
  1212.       || *in == '*' || *in == '.' || *in == '\\'
  1213.       || *in == '?' || *in == '+'
  1214.       || *in == '^' || *in == '$')
  1215.     *out++ = '\\';
  1216.       *out++ = *in;
  1217.     }
  1218.  
  1219.   return make_string (temp, out - temp);
  1220. }
  1221.  
  1222.  
  1223. DEFUN ("compile-regexp", Fcompile_regexp, Scompile_regexp, 1, 1, 0,
  1224.        "Compile regular expression.")
  1225.      (re)
  1226. Lisp_Object re;
  1227. {
  1228.   CHECK_STRING (re, 0);
  1229.   compile_pattern (re, &searchbuf, current_sort_table ());
  1230.   re_compile_fastmap (&searchbuf);
  1231.   return (Fcons (make_string (searchbuf.buffer, searchbuf.used),
  1232.          make_string (search_fastmap, 256)));
  1233. }
  1234.  
  1235. /* This code should be unzapped when there comes to be multiple */
  1236.  /* translation tables.  It has been certified on various cases. */
  1237. /*
  1238. void
  1239. compute_trt_inverse (trt)
  1240.      register unsigned char *trt;
  1241. {
  1242.   register int i = 0400;
  1243.   register unsigned char c, q;
  1244.  
  1245.   while (i--)
  1246.     trt[0400+i] = i;
  1247.   i = 0400;
  1248.   while (i--)
  1249.     {
  1250.       if ((q = trt[i]) != (unsigned char) i)
  1251.     {
  1252.       c = trt[q + 0400];
  1253.       trt[q + 0400] = i;
  1254.       trt[0400 + i] = c;
  1255.     }
  1256.     }
  1257. }
  1258. */
  1259.   
  1260. syms_of_search ()
  1261. {
  1262.   searchbuf.allocated = 100;
  1263.   searchbuf.buffer = (char_t *) malloc (searchbuf.allocated);
  1264.   searchbuf.fastmap = search_fastmap;
  1265.  
  1266.   Qsearch_failed = intern ("search-failed");
  1267.   staticpro (&Qsearch_failed);
  1268.   Qinvalid_regexp = intern ("invalid-regexp");
  1269.   staticpro (&Qinvalid_regexp);
  1270.  
  1271.   Fput (Qsearch_failed, Qerror_conditions,
  1272.     Fcons (Qsearch_failed, Fcons (Qerror, Qnil)));
  1273.   Fput (Qsearch_failed, Qerror_message,
  1274.     build_string ("Search failed"));
  1275.  
  1276.   Fput (Qinvalid_regexp, Qerror_conditions,
  1277.     Fcons (Qinvalid_regexp, Fcons (Qerror, Qnil)));
  1278.   Fput (Qinvalid_regexp, Qerror_message,
  1279.     build_string ("Invalid regexp"));
  1280.  
  1281.   last_regexp = Qnil;
  1282.   staticpro (&last_regexp);
  1283.  
  1284.   defsubr (&Sstring_match);
  1285.   defsubr (&Slooking_at);
  1286.   defsubr (&Sskip_chars_forward);
  1287.   defsubr (&Sskip_chars_backward);
  1288.   defsubr (&Ssearch_forward);
  1289.   defsubr (&Ssearch_backward);
  1290.   defsubr (&Sword_search_forward);
  1291.   defsubr (&Sword_search_backward);
  1292.   defsubr (&Sre_search_forward);
  1293.   defsubr (&Sre_search_backward);
  1294.   defsubr (&Sreplace_match);
  1295.   defsubr (&Smatch_beginning);
  1296.   defsubr (&Smatch_end);
  1297.   defsubr (&Smatch_data);
  1298.   defsubr (&Sstore_match_data);
  1299.   defsubr (&Sregexp_quote);
  1300.   defsubr (&Scompile_regexp);
  1301. }
  1302.